package io.github.lee.repository.jel.domain

import android.os.Parcelable
import androidx.annotation.Keep
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize


@Keep
@Parcelize
data class Item(
    @SerializedName("CanDelete")
    val canDelete: Boolean? = null,
    @SerializedName("CanDownload")
    val canDownload: Boolean? = null,
    @SerializedName("ChannelId")
    val channelId: String? = null,
    @SerializedName("ChildCount")
    val childCount: Int? = null,
    @SerializedName("CollectionType")
    val collectionType: String? = null,
    @SerializedName("DateCreated")
    val dateCreated: String? = null,
    @SerializedName("DisplayPreferencesId")
    val displayPreferencesId: String? = null,
    @SerializedName("EnableMediaSourceDisplay")
    val enableMediaSourceDisplay: Boolean? = null,
    @SerializedName("Etag")
    val etag: String? = null,
    @SerializedName("Id")
    val id: String? = null,
    @SerializedName("IsFolder")
    val isFolder: Boolean? = null,
    @SerializedName("LocalTrailerCount")
    val localTrailerCount: Int? = null,
    @SerializedName("LocationType")
    val locationType: String? = null,
    @SerializedName("LockData")
    val lockData: Boolean? = null,
    @SerializedName("Name")
    val name: String? = null,
    @SerializedName("ParentId")
    val parentId: String? = null,
    @SerializedName("Path")
    val path: String? = null,
    @SerializedName("PlayAccess")
    val playAccess: String? = null,
    @SerializedName("PrimaryImageAspectRatio")
    val primaryImageAspectRatio: Double? = null,
    @SerializedName("ServerId")
    val serverId: String? = null,
    @SerializedName("SortName")
    val sortName: String? = null,
    @SerializedName("SpecialFeatureCount")
    val specialFeatureCount: Int? = null,
    @SerializedName("Type")
    val type: String? = null,
    @SerializedName("UserData")
    val userData: UserData? = null,
    @SerializedName("ProductionYear")
    val productionYear: Int? = null,
    @SerializedName("ParentBackdropItemId")
    val parentBackdropItemId: String? = null,
    @SerializedName("SeasonId")
    val seasonId: String? = null,
    @SerializedName("Overview")
    val overview: String? = null,
    @SerializedName("CommunityRating")
    val communityRating: Double? = 0.0,
    @SerializedName("RunTimeTicks")
    val runTimeTicks: Long? = 0,
    @SerializedName("OfficialRating")
    val officialRating: String? = null,
    @SerializedName("Genres")
    val genres: List<String>? = emptyList(),
    @SerializedName("People")
    val people: List<People>? = emptyList(),
) : Parcelable {

    fun primaryImg(host: String): String {
        val imgId = if (
            type == "Episode"
        ) {
            seasonId
        } else {
            id
        }
        return "$host/Items/$imgId/Images/Primary"
    }

    fun backdropImg(host: String): String {
        val imgId = if (type == "Series"
            || type == "Episode"
        ) {
            parentBackdropItemId
        } else {
            id
        }
        return "$host/Items/$imgId/Images/Backdrop/0"
    }
    // "Primary" "Art" "Backdrop" "Banner" "Logo" "Thumb" "Disc" "Box" "Screenshot" "Menu" "Chapter" "BoxRear" "Profile"


    fun formatGenres(): String {
        val sb = StringBuilder()
        genres?.forEachIndexed { index, s ->
            if (s.isNotEmpty()) {
                sb.append(s)
                if (index != genres.size - 1) {
                    sb.append(",")
                }
            }
        }
        return sb.toString()
    }

}

@Keep
data class ImageBlurHashes(
    @SerializedName("Primary")
    val primary: Primary? = null
)

@Keep
data class ImageTags(
    @SerializedName("Primary")
    val primary: String? = null
)

@Keep
class ProviderIds

@Keep
data class Primary(
    @SerializedName("5eab09ac6e11fbde1f2a9a3113907c53")
    val eab09ac6e11fbde1f2a9a3113907c53: String? = null
)